﻿Public Class clsFLBck

    Public Function intoCK(en As entity_flb_ck) As Integer
        Dim sql As String = ""
        Dim rtn As Integer
        DBacs.BeginTransaction()
        Try
            sql &= "INSERT INTO sf.b_flb_ck(factory_id, dl_no, piece_num, which_side, flb_type, flb_info_sys_id, pgd_id, material_code, exprie_date, location, begin_date, status, into_ope, update_time) "
            sql &= "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?,(SELECT CURRENT_TIMESTAMP(6)),?,?,(SELECT CURRENT_TIMESTAMP(6)))"
            With en
                rtn = DBacs.ExecuteUpdateSql(sql, -1， .factory_id, .dl_no, .piece_num, .which_side, .flb_type, .flb_info_sys_id, .pgd_id, .material_code, .exprie_date, .location, .status, .into_ope)
            End With

            sql = ""
            sql &= "UPDATE sf.b_flb_info "
            sql &= "SET status = ?, update_time=(SELECT CURRENT_TIMESTAMP(6)) "
            sql &= "WHERE sys_id = ? "
            rtn = DBacs.ExecuteUpdateSql(sql, -1， "1", en.flb_info_sys_id)

            sql = ""
            sql &= "UPDATE sf.t_mst_list "
            sql &= "SET param2 = ?, update_time=(SELECT CURRENT_TIMESTAMP(6)) "
            sql &= "WHERE factory_id = ? and mst_type = ? and mst_value = ? AND param1 = ? "
            rtn = DBacs.ExecuteUpdateSql(sql, -1， "1", "TS", "07", en.location, "1")
            DBacs.CommitTransaction()
        Catch ex As Exception
            DBacs.RollbackTransaction()
            rtn = -2
        End Try
        Return rtn
    End Function

    Public Function outCK(_loc As String, _sys_id As Integer, oper As String) As Integer
        Dim sql As String = ""
        Dim rtn As Integer = 0
        DBacs.BeginTransaction()
        Try
            sql &= " UPDATE sf.b_flb_ck "
            sql &= " SET end_date = (SELECT CURRENT_TIMESTAMP(6)) , status = ?, out_ope = ? "
            sql &= " WHERE factory_id = ? and sys_id = ? "

            rtn = DBacs.ExecuteUpdateSql(sql, -1, "1", oper, "TS", _sys_id)

            sql = ""
            sql &= "UPDATE sf.t_mst_list "
            sql &= "SET param2 = ?, update_time=(SELECT CURRENT_TIMESTAMP(6)) "
            sql &= "WHERE factory_id = ? "
            sql &= "    and mst_type = ? "
            sql &= "    and mst_value = ? "
            sql &= "  AND param1 = ? "
            rtn = DBacs.ExecuteUpdateSql(sql, -1, "0", "TS", "07", _loc, "1")
            DBacs.CommitTransaction()
        Catch ex As Exception
            DBacs.RollbackTransaction()
            rtn = -2
        End Try
        Return rtn
    End Function

    Public Function getListALL() As DataTable
        Dim szSql As String = ""
        szSql &= " select * from sf.b_flb_ck WHERE factory_id = ? "
        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, "TS")
        If IsNothing(dt) Then
            getListALL = New DataTable
        Else
            getListALL = dt
        End If
    End Function

    Public Function getListByDlNo(dl_no As String, status As String) As DataTable
        Dim szSql As String = ""
        szSql &= " select * from sf.b_flb_ck WHERE factory_id = ? and dl_no = ? and status = ?"
        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, "TS", dl_no, status)
        If IsNothing(dt) Then
            getListByDlNo = New DataTable
        Else
            getListByDlNo = dt
        End If
    End Function

End Class
